package healththink



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Attribute)
class AttributeTests {

    void testFacilityAttribute() {
		
		def faTest = HealthThink.getStaticFacilityAttribute()
		mockForConstraintsTests(Attribute, [faTest])
		def faTest1 = new Attribute()
		assertFalse faTest1.validate()
		assertEquals "nullable", faTest1.errors["name"]
		
		def faTest10 = new Attribute(name: "nonUnique")
		def faTest11 = new Attribute(name: "nonUnique")
		faTest10 = faTest10.save(flush:true)
		assertFalse faTest11.validate()
		assertEquals "unique", faTest11.errors["name"]
		faTest10.delete(flush:true)
		
		/* implementation */
		User user = HealthThink.getStaticUser()
		Attribute target = HealthThink.getStaticFacilityAttribute()
		assertNotNull("(error)FacilityAttribute Target Null", target)
		assertNotNull("(error)FacilityAttribute Validation Was Successfull", target.validate())
		target.user = user
	   
		//this is parent, it must save
		target = target.save(flush:true)
		Attribute expected = Attribute.findById(target.id)
	   
		assertNotNull("(error)FacilityAttribute Target was not saved", target)
		assertNotNull("(error)Expected FacilityAttribute was null", expected)
		assertEquals("(error) FacilityAttribute target not equal to expected.", target, expected)
	   
		target.delete(flush:true)
    }
}
